/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \class ETFUnpackTask
  \brief abstract base class for tasks in the unpacking stage
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-10-04
  \date 2021-10-04 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-10-04   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFUnpackTask_h
#define ETFUnpackTask_h

#include "ETFTask.h"

class TH1F;
class TH1D;
class TH2F;

class ETFUnpackTask : public ETFTask{
public:
  ETFUnpackTask(const char *name = "UnpackTask");
  virtual ~ETFUnpackTask();

  virtual void Exec() override;
  void SetDebug(bool opt = true){ fDebug = opt; }

  // ClassDefOverride(ETFUnpackTask, 1); // abstract base class for tasks in the unpacking stage

protected:
  virtual void CreateHistos() override; ///< create histograms for filling

  bool fDebug; // debug or not
  int fRTSca[16]; ///< clears upon each reset signal from online-GUI

  TH1F *hSecLenPXI; ///< PXI event length
  TH1F *hSecLenVME; ///< VME event length
  TH2F *h2SecLenPXI; ///< PXI event length - unpacker
  TH2F *h2SecLenVME; ///< VME event length - unpacker
  TH1F *hCh, *hChv, *haCh; ///< channel distribution
  TH2F *hFragLen; ///< data length of each fragment, containing possible tables
  TH2F *htot, *htotV; ///< time To trig
  TH2F *hnlvsChid, *hntvsChid; ///< number of leading and trailing edges v.s. chid
  TH2F *hnl_ntvsChid; ///< number of leading edges - number of trailing edges v.s. chid
  TH1F *ha; ///< for amplitude channels -- amplitude
  TH2F *hac, *hqdc; ///< for amplitude channels -- amplitude v.s. channel id
  TH1D *hRTsca, *hsca, *hdsca; ///< scaler, RT: real time
  TH1F *hdIndex; ///< for PXI v.s. VME align check
  TH1F *hpxiMonitor, *hvmeMonitor; ///< event index monitor

  // time-to-trig: for inspection of the micro time structure of the beam cycle
  TH2F *hTimeToTrigCE[4]; ///< TimeToTrig v.s. chid - [0-3] pulse
  TH2F *hTimeToTrigC, *hTimeToTrigCV; ///< TimeToTrig v.s. chid - all pulses
  TH2F *hTimeToTrigE; ///< TimeToTrig v.s. # Edge
  TH1F *hTimeToTrig; ///< TimeToTrig v.s. for all
};

#endif
